package com.audaque.springboot.foshanupload.web.quartzdemo.job;

import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.PersistJobDataAfterExecution;

/**
 * @author zgb
 * @desc 有状态的 job 可以理解为多次 job调用期间可以持有一些状态信息，这些状态信息存储在JobDataMap中。
 * @date 2023-04-30 13:02:39
 */
//多次调用 Job 的时候，将参数保留在 JobDataMap
@PersistJobDataAfterExecution
public class MyStatusJob implements Job {
    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {
        System.out.println("任务被执行了。。。");
        context.getTrigger().getJobDataMap().get("tiggerDataMap");
        long count = (long) context.getJobDetail().getJobDataMap().get("count");
        System.out.println("当前执行，第" + count + "次");
        context.getJobDetail().getJobDataMap().put("count", ++count);
    }
}
